package com.ruoyi.service.impl;

import com.ruoyi.domain.BrandInfo;
import com.ruoyi.domain.CategoryBrand;
import com.ruoyi.mapper.BrandInfoMapper;
import com.ruoyi.mapper.CategoryBrandMapper;
import com.ruoyi.service.IBrandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 */
@Service
public class BrandInfoServiceImpl implements IBrandInfoService {

    @Autowired
    private BrandInfoMapper brandInfoMapper;

    @Override
    public List<BrandInfo> selectAll() {
        return brandInfoMapper.selectList();
    }

    @Override
    public BrandInfo selectById(Long id) {
        return brandInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insertOne(BrandInfo brandInfo) {
        return brandInfoMapper.insertSelective(brandInfo);
    }

    @Override
    public int updateById(BrandInfo brandInfo) {
        return brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
    }

    @Override
    public int deleteByIds(Long[] ids) {
        return brandInfoMapper.deleteByPrimaryKey(ids);
    }

    @Override
    public List<BrandInfo> selectPage(BrandInfo brandInfo) {
        return brandInfoMapper.selectPage(brandInfo);
    }

    @Override
    public List<BrandInfo> selectBrandInfoListAll() {

        List<BrandInfo> brandInfos = brandInfoMapper.selectBrandInfoListAll();

        for (BrandInfo brandInfo : brandInfos) {

            System.out.println("brandInfoConeIdsStr = " + brandInfo.getConeIdsStr());

            List<Integer> categoryBrands =new ArrayList<>();

            if (brandInfo.getConeIdsStr()!=null){
                String[] ss = brandInfo.getConeIdsStr().split(",");

                for(String s:ss) {
                    categoryBrands.add(Integer.parseInt(s));
                }
            }

            brandInfo.setConeIds(categoryBrands);

        }
        return brandInfos;
    }



}
